#include "StdAfx.h"
#include "GoBoard.h"


void CGoBoard::Init(void)
{
	ASSERT(m_LineCount >= 3 && m_LineCount <= 19);

	InitOneBoard(BLACK_COLOR);
	InitOneBoard(WHITE_COLOR);
}


void CGoBoard::Copy(const CGoBoard &source)
{
	ASSERT(m_LineCount == source.m_LineCount);

	m_OneColorBoard[BLACK_COLOR] = source.m_OneColorBoard[BLACK_COLOR];
	m_OneColorBoard[WHITE_COLOR] = source.m_OneColorBoard[WHITE_COLOR];
}


void CGoBoard::Clear(void)
{
	ClearOneBoard(BLACK_COLOR);
	ClearOneBoard(WHITE_COLOR);
}


void CGoBoard::InitOneBoard(TPlayerColor color)
{
	ASSERT(color == BLACK_COLOR || color == WHITE_COLOR);

	int square = m_LineCount * m_LineCount;
	TOneColorGoBoard newVector(square, EMPTY_ON_POINT);
	m_OneColorBoard[color].swap(newVector);
	//m_OneColorBoard[color].resize(square);
	//fill_n(m_OneColorBoard[color].begin(), square, EMPTY_ON_POINT);
}


void CGoBoard::ClearOneBoard(TPlayerColor color)
{
	ASSERT(color == BLACK_COLOR || color == WHITE_COLOR);

	fill_n(m_OneColorBoard[color].begin(), m_LineCount * m_LineCount, EMPTY_ON_POINT);
}


#ifdef _DEBUG
void CGoBoard::Print(void)
{
	for (int i=0; i<m_LineCount; i++) {
		for (int j=0; j<m_LineCount; j++) {
			size_t script = i * m_LineCount + j;
			ASSERT(m_OneColorBoard[BLACK_COLOR][script] == EMPTY_ON_POINT ||
				m_OneColorBoard[WHITE_COLOR][script] == EMPTY_ON_POINT);
			if (m_OneColorBoard[BLACK_COLOR][script] == PIECE_ON_POINT) {
				TRACE("*  ");
			} else if (m_OneColorBoard[WHITE_COLOR][script] == PIECE_ON_POINT) {
				TRACE("O  ");
			} else {
				TRACE("+  ");
			}
		}
		TRACE("\n");
	}
	TRACE("\n\n\n");
}
#endif